const { ApiController } = require('jax')

class AdminApiController extends ApiController {
  /**
   * 超级管理员（平台管理员）
   */
  get isSuperAdmin() {
    const { ctx } = this
    const { admin } = ctx.state

    return admin.systemType == 'admin' && admin.isAdmin
  }

  // 用户
  get user() {
    return this.ctx.state.admin
  }

  // 用户ID
  get adminId() {
    return this.ctx.state.admin.adminId || this.ctx.state.admin.id
  }

  // 企业ID
  get companyId() {
    return this.ctx.state.admin?.source?.companyId
  }

  // 用户ID
  get userId() {
    return this.ctx.state.admin.source.userId
  }

  // 平台系统
  get isPlatform() {
    const { ctx } = this
    const { admin } = ctx.state

    return admin.systemType == 'admin'
  }

  // 单位系统
  get isCompany() {
    const { ctx } = this
    const { admin } = ctx.state

    return admin.systemType == 'company'
  }

  // 个人系统
  get isUser() {
    const { ctx } = this
    const { admin } = ctx.state

    return admin.systemType == 'user'
  }

  // 操作员
  get operator() {
    return this.ctx.state.admin?.source?.operatorId
  }

  // 操作员
  get operatorId() {
    return this.ctx.state.admin?.source?.operatorId
  }
}

module.exports = AdminApiController
